<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>输入过滤</title>
</head>
<body>
    <label for="username">
        用户名
    </label>
    <input type="text" id="username">
</body>
<script>
    // 1. 屏蔽字符
    const inputDOM = document.getElementById('username');
    inputDOM.addEventListener('keypress',(event)=>{
        console.log(event.target.value)
        if(!/\d/.test(String.fromCharCode(event.charCode))){
            event.preventDefault(); //禁止默认行为  只能禁止英文字符输入，无法禁止汉字字符输入
        }
    })
</script>
</html>